package com.xinsoft.controller.basic;

import com.alibaba.fastjson.JSONObject;
import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysUserDTO;
import com.xinsoft.service.SysUserService;
import com.xinsoft.utils.SpringUtils;
import com.xinsoft.websocket.WebSocketSessionHolderManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ws/test")
public class TestController {

    private static WebSocketSessionHolderManager sessionHolderManager = SpringUtils.getBean(WebSocketSessionHolderManager.class);

    @Autowired
    private SysUserService userService;

    /**
     * @Author Li9527
     * @Description 发送消息
     * @Date 2023/4/23 16:38
     * @return com.xinsoft.common.Response<?>
     **/
    @GetMapping("/send")
    public Response<?> send() {
        SysUserDTO sysUser = userService.getSysUser(62);
        sessionHolderManager.sendMessage("10086", JSONObject.toJSONString(sysUser));
        return Response.succeed("发送成功");
    }
}
